home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / man / lib / tk / ConfigWidg.man < prev    next >
Encoding:
Text File  |  1992-08-24  |  30.1 KB  |  788 lines

  1. '\"
  2. '\" Copyright 1990-1992 Regents of the University of California
  3. '\" Permission to use, copy, modify, and distribute this
  4. '\" documentation for any purpose and without fee is hereby
  5. '\" granted, provided that this notice appears in all copies.
  6. '\" The University of California makes no representations about
  7. '\" the suitability of this material for any purpose.  It is
  8. '\" provided "as is" without express or implied warranty.
  9. '\" 
  10. '\" $Header: /user6/ouster/wish/man/RCS/ConfigWidg.man,v 1.13 92/08/06 09:04:13 ouster Exp $ SPRITE (Berkeley)
  11. '\" 
  12. .\" The definitions below are for supplemental macros used in Sprite
  13. .\" manual entries.
  14. .\"
  15. .\" .HS name section [date [version]]
  16. .\"    Replacement for .TH in other man pages.  See below for valid
  17. .\"    section names.
  18. .\"
  19. .\" .AP type name in/out [indent]
  20. .\"    Start paragraph describing an argument to a library procedure.
  21. .\"    type is type of argument (int, etc.), in/out is either "in", "out",
  22. .\"    or "in/out" to describe whether procedure reads or modifies arg,
  23. .\"    and indent is equivalent to second arg of .IP (shouldn't ever be
  24. .\"    needed;  use .AS below instead)
  25. .\"
  26. .\" .AS [type [name]]
  27. .\"    Give maximum sizes of arguments for setting tab stops.  Type and
  28. .\"    name are examples of largest possible arguments that will be passed
  29. .\"    to .AP later.  If args are omitted, default tab stops are used.
  30. .\"
  31. .\" .BS
  32. .\"    Start box enclosure.  From here until next .BE, everything will be
  33. .\"    enclosed in one large box.
  34. .\"
  35. .\" .BE
  36. .\"    End of box enclosure.
  37. .\"
  38. .\" .VS
  39. .\"    Begin vertical sidebar, for use in marking newly-changed parts
  40. .\"    of man pages.
  41. .\"
  42. .\" .VE
  43. .\"    End of vertical sidebar.
  44. .\"
  45. .\" .DS
  46. .\"    Begin an indented unfilled display.
  47. .\"
  48. .\" .DE
  49. .\"    End of indented unfilled display.
  50. .\"
  51. '\"    # Heading for Sprite man pages
  52. .de HS
  53. .if '\\$2'cmds'       .TH \\$1 1 \\$3 \\$4
  54. .if '\\$2'lib'        .TH \\$1 3 \\$3 \\$4
  55. .if '\\$2'tcl'        .TH \\$1 3 \\$3 \\$4
  56. .if '\\$2'tk'         .TH \\$1 3 \\$3 \\$4
  57. .if t .wh -1.3i ^B
  58. .nr ^l \\n(.l
  59. .ad b
  60. ..
  61. '\"    # Start an argument description
  62. .de AP
  63. .ie !"\\$4"" .TP \\$4
  64. .el \{\
  65. .   ie !"\\$2"" .TP \\n()Cu
  66. .   el          .TP 15
  67. .\}
  68. .ie !"\\$3"" \{\
  69. .ta \\n()Au \\n()Bu
  70. \&\\$1    \\fI\\$2\\fP    (\\$3)
  71. .\".b
  72. .\}
  73. .el \{\
  74. .br
  75. .ie !"\\$2"" \{\
  76. \&\\$1    \\fI\\$2\\fP
  77. .\}
  78. .el \{\
  79. \&\\fI\\$1\\fP
  80. .\}
  81. .\}
  82. ..
  83. '\"    # define tabbing values for .AP
  84. .de AS
  85. .nr )A 10n
  86. .if !"\\$1"" .nr )A \\w'\\$1'u+3n
  87. .nr )B \\n()Au+15n
  88. .\"
  89. .if !"\\$2"" .nr )B \\w'\\$2'u+\\n()Au+3n
  90. .nr )C \\n()Bu+\\w'(in/out)'u+2n
  91. ..
  92. '\"    # BS - start boxed text
  93. '\"    # ^y = starting y location
  94. '\"    # ^b = 1
  95. .de BS
  96. .br
  97. .mk ^y
  98. .nr ^b 1u
  99. .if n .nf
  100. .if n .ti 0
  101. .if n \l'\\n(.lu\(ul'
  102. .if n .fi
  103. ..
  104. '\"    # BE - end boxed text (draw box now)
  105. .de BE
  106. .nf
  107. .ti 0
  108. .mk ^t
  109. .ie n \l'\\n(^lu\(ul'
  110. .el \{\
  111. .\"    Draw four-sided box normally, but don't draw top of
  112. .\"    box if the box started on an earlier page.
  113. .ie !\\n(^b-1 \{\
  114. \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
  115. .\}
  116. .el \}\
  117. \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
  118. .\}
  119. .\}
  120. .fi
  121. .br
  122. .nr ^b 0
  123. ..
  124. '\"    # VS - start vertical sidebar
  125. '\"    # ^Y = starting y location
  126. '\"    # ^v = 1 (for troff;  for nroff this doesn't matter)
  127. .de VS
  128. .mk ^Y
  129. .ie n 'mc \s12\(br\s0
  130. .el .nr ^v 1u
  131. ..
  132. '\"    # VE - end of vertical sidebar
  133. .de VE
  134. .ie n 'mc
  135. .el \{\
  136. .ev 2
  137. .nf
  138. .ti 0
  139. .mk ^t
  140. \h'|\\n(^lu+3n'\L'|\\n(^Yu-1v\(bv'\v'\\n(^tu+1v-\\n(^Yu'\h'-|\\n(^lu+3n'
  141. .sp -1
  142. .fi
  143. .ev
  144. .\}
  145. .nr ^v 0
  146. ..
  147. '\"    # Special macro to handle page bottom:  finish off current
  148. '\"    # box/sidebar if in box/sidebar mode, then invoked standard
  149. '\"    # page bottom macro.
  150. .de ^B
  151. .ev 2
  152. 'ti 0
  153. 'nf
  154. .mk ^t
  155. .if \\n(^b \{\
  156. .\"    Draw three-sided box if this is the box's first page,
  157. .\"    draw two sides but no top otherwise.
  158. .ie !\\n(^b-1 \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c
  159. .el \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c
  160. .\}
  161. .if \\n(^v \{\
  162. .nr ^x \\n(^tu+1v-\\n(^Yu
  163. \kx\h'-\\nxu'\h'|\\n(^lu+3n'\ky\L'-\\n(^xu'\v'\\n(^xu'\h'|0u'\c
  164. .\}
  165. .bp
  166. 'fi
  167. .ev
  168. .if \\n(^b \{\
  169. .mk ^y
  170. .nr ^b 2
  171. .\}
  172. .if \\n(^v \{\
  173. .mk ^Y
  174. .\}
  175. ..
  176. '\"    # DS - begin display
  177. .de DS
  178. .RS
  179. .nf
  180. .sp
  181. ..
  182. '\"    # DE - end display
  183. .de DE
  184. .fi
  185. .RE
  186. .sp .5
  187. ..
  188. .HS Tk_ConfigureWidget tk
  189. .BS
  190. .SH NAME
  191. Tk_ConfigureWidget, Tk_Offset, Tk_ConfigureInfo \- process configuration options for widgets
  192. .SH SYNOPSIS
  193. .nf
  194. \fB#include <tk.h>\fR
  195. .sp
  196. int
  197. \fBTk_ConfigureWidget(\fIinterp, tkwin, specs, argc, argv, widgRec, flags\fB)\fR
  198. .sp
  199. int
  200. \fBTk_Offset(\fItype, field\fB)\fR
  201. .sp
  202. int
  203. \fBTk_ConfigureInfo(\fIinterp, tkwin, specs, widgRec, argvName, flags\fB)\fR
  204. .SH ARGUMENTS
  205. .AS Tk_ConfigSpec *widgRec
  206. .AP Tcl_Interp *interp in
  207. Interpreter to use for returning error messages.
  208. .AP Tk_Window tkwin in
  209. Window used to represent widget (needed to set up X resources).
  210. .AP Tk_ConfigSpec *specs in
  211. Pointer to table specifying legal configuration options for this
  212. widget.
  213. .AP int argc in
  214. Number of arguments in \fIargv\fR.
  215. .AP char **argv in
  216. Command-line options for configuring widget.
  217. .AP char *widgRec in/out
  218. Points to widget record structure.  Fields in this structure get
  219. modified by \fBTk_ConfigureWidget\fR to hold configuration information.
  220. .AP int flags in
  221. If non-zero, then it specifies one or more flags that control the
  222. processing of configuration information.  Different flags may be OR'ed
  223. together.  The only flag currently defined is TK_CONFIG_ARGV_ONLY.
  224. .AP char *argvName in
  225. The name used on Tcl command lines to refer to a particular option
  226. (e.g. when creating a widget or invoking the \fBconfigure\fR widget
  227. command).  If non-NULL, then information is returned only for this
  228. option.  If NULL, then information is returned for all available
  229. options.
  230. .AP "type name" type in
  231. The name of the type of a widget record.
  232. .AP "field name" field in
  233. The name of a field in records of type \fItype\fR.
  234. .BE
  235. .SH DESCRIPTION
  236. .PP
  237. \fBTk_ConfigureWidget\fR is called to configure various aspects of a
  238. widget, such as colors, fonts, border width, etc.
  239. It is intended as a convenience procedure to reduce the amount
  240. of code that must be written in individual widget managers to
  241. handle configuration information.
  242. It is typically
  243. invoked when widgets are created, and again when the \fBconfigure\fR
  244. command is invoked for a widget.
  245. Although intended primarily for widgets, \fBTk_ConfigureWidget\fR
  246. can be used in other situations where \fIargc-argv\fR information
  247. is to be used to fill in a record structure, such as configuring
  248. graphical elements for a canvas widget or entries of a menu.
  249. .PP
  250. \fBTk_ConfigureWidget\fR processes
  251. a table specifying the configuration options that are supported
  252. (\fIspecs\fR) and a collection of command-line arguments (\fIargc\fR and
  253. \fIargv\fR) to fill in fields of a record (\fIwidgRec\fR).
  254. It uses the option database and defaults specified in \fIspecs\fR
  255. to fill in fields of \fIwidgRec\fR that are not specified in \fIargv\fR.
  256. \fBTk_ConfigureWidget\fR normally returns the value TCL_OK; in this
  257. case it does not modify \fIinterp\fR.  If an error
  258. occurs then TCL_ERROR is returned and \fBTk_ConfigureWidget\fR will
  259. leave an error message in \fIinterp->result\fR in the standard Tcl
  260. fashion.  In
  261. the event of an error return, some of the fields of \fIwidgRec\fR
  262. could already have been modified, if configuration information for them
  263. was successfully processed before the error occurred.
  264. .PP
  265. The \fIspecs\fR array specifies the kinds of configuration options
  266. expected by the widget.  Each of its entries specifies one configuration
  267. option and has the following structure:
  268. .DS
  269. .ta 1c 2c 3c
  270. typedef struct {
  271.     int \fItype\fR;
  272.     char \fIargvName\fR;
  273.     char *\fIdbName\fR;
  274.     char *\fIdbClass\fR;
  275.     char *\fIdefValue\fR;
  276.     int \fIoffset\fR;
  277.     int \fIspecFlags\fR;
  278. .VS
  279.     Tk_CustomOption *\fIcustomPtr\fR;
  280. .VE
  281. } Tk_ConfigSpec;
  282. .DE
  283. .LP
  284. The \fItype\fR field indicates what type of configuration option this is
  285. (e.g. TK_CONFIG_COLOR for a color value, or TK_CONFIG_INT for
  286. an integer value).  The \fItype\fR field indicates how to use the
  287. value of the option (more on this below).
  288. The \fIargvName\fR field is a string such as ``\-font'' or ``\-bg'',
  289. which is compared with the values in \fIargv\fR (if \fIargvName\fR is
  290. NULL it means this is a grouped entry;  see GROUPED ENTRIES below).  The
  291. \fIdbName\fR and \fIdbClass\fR fields are used to look up a value
  292. for this option in the option database.  The \fIdefValue\fR field
  293. specifies a default value for this configuration option if no
  294. value is specified in either \fIargv\fR or the option database.
  295. \fIOffset\fR indicates where in \fIwidgRec\fR to store information
  296. about this option, and \fIspecFlags\fR contains additional information
  297. to control the processing of this configuration option (see FLAGS
  298. below).
  299. The last field, \fIcustomPtr\fR, is only used if \fItype\fR is
  300. TK_CONFIG_CUSTOM;  see CUSTOM OPTION TYPES below.
  301. .PP
  302. \fBTk_ConfigureWidget\fR first processes \fIargv\fR to see which
  303. (if any) configuration options are specified there.  \fIArgv\fR
  304. must contain an even number of fields;  the first of each pair
  305. of fields must match the \fIargvName\fR of some entry in \fIspecs\fR
  306. (unique abbreviations are acceptable),
  307. and the second field of the pair contains the value for that
  308. configuration option.  If there are entries in \fIspec\fR for which
  309. there were no matching entries in \fIargv\fR,
  310. \fBTk_ConfigureWidget\fR uses the \fIdbName\fR and \fIdbClass\fR
  311. fields of the \fIspecs\fR entry to probe the option database;  if
  312. a value is found, then it is used as the value for the option.
  313. Finally, if no entry is found in the option database, the
  314. \fIdefValue\fR field of the \fIspecs\fR entry is used as the
  315. value for the configuration option.  If the \fIdefValue\fR is
  316. NULL, or if the TK_CONFIG_DONT_SET_DEFAULT bit is set in
  317. \fIflags\fR, then there is no default value and this \fIspecs\fR entry
  318. will be ignored if no value is specified in \fIargv\fR or the
  319. option database.
  320. .PP
  321. Once a string value has been determined for a configuration option,
  322. \fBTk_ConfigureWidget\fR translates the string value into a more useful
  323. form, such as a color if \fItype\fR is TK_CONFIG_COLOR or an integer
  324. if \fItype\fR is TK_CONFIG_INT.  This value is then stored in the
  325. record pointed to by \fIwidgRec\fR.  This record is assumed to
  326. contain information relevant to the manager of the widget;  its exact
  327. type is unknown to \fBTk_ConfigureWidget\fR.  The \fIoffset\fR field
  328. of each \fIspecs\fR entry indicates where in \fIwidgRec\fR to store
  329. the information about this configuration option.  You should use the
  330. \fBTk_Offset\fR macro to generate \fIoffset\fR values (see below for
  331. a description of \fBTk_Offset\fR).  The location indicated by
  332. \fIwidgRec\fR and \fIoffset\fR will be referred to as the ``target''
  333. in the descriptions below.
  334. .PP
  335. The \fItype\fR field of each entry in \fIspecs\fR determines what
  336. to do with the string value of that configuration option.  The
  337. legal values for \fItype\fR, and the corresponding actions, are:
  338. .TP
  339. \fBTK_CONFIG_ACTIVE_CURSOR\fR
  340. The value
  341. .VS
  342. must be an ASCII string identifying a cursor in a form
  343. suitable for passing to \fBTk_GetCursor\fR. 
  344. The value is converted to a \fBCursor\fR by calling
  345. \fBTk_GetCursor\fR and the result is stored in the target.
  346. In addition, the resulting cursor is made the active cursor
  347. for \fItkwin\fR by calling \fBXDefineCursor\fR.
  348. If TK_CONFIG_NULL_OK is specified in \fIspecFlags\fR then the value
  349. may be an empty string, in which case the target and \fItkwin\fR's
  350. active cursor will be set to \fBNone\fR.
  351. If the previous value of the target
  352. wasn't \fBNone\fR, then it is freed by passing it to \fBTk_FreeCursor\fR.
  353. .TP
  354. \fBTK_CONFIG_ANCHOR\fR
  355. The value must be an ASCII string identifying an anchor point in one of the ways
  356. accepted by \fBTk_GetAnchor\fR.
  357. The string is converted to a \fBTk_Anchor\fR by calling
  358. \fBTk_GetAnchor\fR and the result is stored in the target.
  359. .VE
  360. .TP
  361. \fBTK_CONFIG_BITMAP\fR
  362. The value must be an ASCII string identifying a bitmap in a form
  363. suitable for passing to \fBTk_GetBitmap\fR.  The value is converted
  364. to a \fBPixmap\fR by calling \fBTk_GetBitmap\fR and the result
  365. is stored in the target.
  366. .VS
  367. If TK_CONFIG_NULL_OK is specified in \fIspecFlags\fR then the value
  368. may be an empty string, in which case the target is set to \fBNone\fR.
  369. .VE
  370. If the previous value of the target
  371. wasn't \fBNone\fR, then it is freed by passing it to \fBTk_FreeBitmap\fR.
  372. .TP
  373. \fBTK_CONFIG_BOOLEAN\fR
  374. The value must be an ASCII string specifying a boolean value.  Any
  375. of the values ``true'', ``yes'', ``on'', or ``1'',
  376. or an abbreviation of one of these values, means true;
  377. any of the values ``false'', ``no'', ``off'', or ``0'', or an abbreviation of
  378. one of these values, means false.
  379. The target is expected to be an integer;  for true values it will
  380. be set to 1 and for false values it will be set to 0.
  381. .TP
  382. \fBTK_CONFIG_BORDER\fR
  383. The value must be an ASCII string identifying a border color in a form
  384. suitable for passing to \fBTk_Get3DBorder\fR.  The value is converted
  385. to a (\fBTk_3DBorder *\fR) by calling \fBTk_Get3DBorder\fR and the result
  386. is stored in the target.
  387. .VS
  388. If TK_CONFIG_NULL_OK is specified in \fIspecFlags\fR then the value
  389. may be an empty string, in which case the target will be set to NULL.
  390. .VE
  391. If the previous value of the target
  392. wasn't NULL, then it is freed by passing it to \fBTk_Free3DBorder\fR.
  393. .TP
  394. \fBTK_CONFIG_CAP_STYLE\fR
  395. The value must be
  396. .VS
  397. an ASCII string identifying a cap style in one of the ways
  398. accepted by \fBTk_GetCapStyle\fR.
  399. The string is converted to an integer value corresponding
  400. to the cap style by calling
  401. \fBTk_GetCapStyle\fR and the result is stored in the target.
  402. .VE
  403. .TP
  404. \fBTK_CONFIG_COLOR\fR
  405. The value must be an ASCII string identifying a color in a form
  406. suitable for passing to \fBTk_GetColor\fR.  The value is converted
  407. to an (\fBXColor *\fR) by calling \fBTk_GetColor\fR and the result
  408. is stored in the target.
  409. .VS
  410. If TK_CONFIG_NULL_OK is specified in \fIspecFlags\fR then the value
  411. may be an empty string, in which case the target will be set to \fBNone\fR.
  412. .VE
  413. If the previous value of the target
  414. wasn't NULL, then it is freed by passing it to \fBTk_FreeColor\fR.
  415. .TP
  416. \fBTK_CONFIG_CURSOR\fR
  417. This option is identical to \fBTK_CONFIG_ACTIVE_CURSOR\fR except
  418. that the new cursor is not made the active one for \fItkwin\fR.
  419. .TP
  420. \fBTK_CONFIG_CUSTOM\fR
  421. .VS
  422. This option allows applications to define new option types.
  423. The \fIcustomPtr\fR field of the entry points to a structure
  424. defining the new option type.
  425. See the section CUSTOM OPTION TYPES below for details.
  426. .VE
  427. .TP
  428. \fBTK_CONFIG_DOUBLE\fR
  429. The value must be an ASCII floating-point number in
  430. the format accepted by \fBstrtol\fR.  The string is converted
  431. to a \fBdouble\fR value, and the value is stored in the
  432. target.
  433. .TP
  434. \fBTK_CONFIG_END\fR
  435. Marks the end of the table.  The last entry in \fIspecs\fR
  436. must have this type;  all of its other fields are ignored and it
  437. will never match any arguments.
  438. .TP
  439. \fBTK_CONFIG_FONT\fR
  440. The value must be an ASCII string identifying a font in a form
  441. suitable for passing to \fBTk_GetFontStruct\fR.  The value is converted
  442. to an (\fBXFontStruct *\fR) by calling \fBTk_GetFontStruct\fR and the result
  443. is stored in the target.
  444. .VS
  445. If TK_CONFIG_NULL_OK is specified in \fIspecFlags\fR then the value
  446. may be an empty string, in which case the target will be set to NULL.
  447. .VE
  448. If the previous value of the target
  449. wasn't NULL, then it is freed by passing it to \fBTk_FreeFontStruct\fR.
  450. .TP
  451. \fBTK_CONFIG_INT\fR
  452. The value must be an ASCII integer string
  453. in the format accepted by \fBstrtol\fR (e.g. ``0''
  454. and ``0x'' prefixes may be used to specify octal or hexadecimal
  455. numbers, respectively).  The string is converted to an integer
  456. value and the integer is stored in the target.
  457. .TP
  458. \fBTK_CONFIG_JOIN_STYLE\fR
  459. The value must be
  460. .VS
  461. an ASCII string identifying a join style in one of the ways
  462. accepted by \fBTk_GetJoinStyle\fR.
  463. The string is converted to an integer value corresponding
  464. to the join style by calling
  465. \fBTk_GetJoinStyle\fR and the result is stored in the target.
  466. .TP
  467. \fBTK_CONFIG_JUSTIFY\fR
  468. The value must be
  469. an ASCII string identifying a justification method in one of the
  470. ways accepted by \fBTk_GetJustify\fR.
  471. The string is converted to a \fBTk_Justify\fR by calling
  472. \fBTk_GetJustify\fR and the result is stored in the target.
  473. .TP
  474. \fBTK_CONFIG_MM\fR
  475. The value must specify a screen distance in one of the forms acceptable
  476. to \fBTk_GetScreenMM\fR.
  477. The string is converted to double-precision floating-point distance
  478. in millimeters and the value is stored in the target.
  479. .TP
  480. \fBTK_CONFIG_PIXELS\fR
  481. The value must specify screen units in one of the forms acceptable
  482. to \fBTk_GetPixels\fR.
  483. The string is converted to an integer distance in pixels and the
  484. value is stored in the target.
  485. .VE
  486. .TP
  487. \fBTK_CONFIG_RELIEF\fR
  488. The value must be an ASCII string identifying a relief in a form
  489. suitable for passing to \fBTk_GetRelief\fR.  The value is converted
  490. to an integer relief value by calling \fBTk_GetRelief\fR and the result
  491. is stored in the target.
  492. .TP
  493. \fBTK_CONFIG_STRING\fR
  494. A copy
  495. .VS
  496. of the value is made by allocating memory space with
  497. \fBmalloc\fR and copying the value into the dynamically-allocated
  498. space.  A pointer to the new string is stored in the target.
  499. If TK_CONFIG_NULL_OK is specified in \fIspecFlags\fR then the value
  500. may be an empty string, in which case the target will be set to NULL.
  501. If the previous value of the target wasn't NULL, then it is
  502. freed by passing it to \fBfree\fR.
  503. .VE
  504. .TP
  505. \fBTK_CONFIG_SYNONYM\fR
  506. This \fItype\fR value identifies special entries in \fIspecs\fR that
  507. are synonyms for other entries.  If an \fIargv\fR value matches the
  508. \fIargvName\fR of a TK_CONFIG_SYNONYM entry, the entry isn't used
  509. directly. Instead, \fBTk_ConfigureWidget\fR searches \fIspecs\fR
  510. for another entry whose \fIargvName\fR is the same as the \fIdbName\fR
  511. field in the TK_CONFIG_SYNONYM entry;  this new entry is used just
  512. as if its \fIargvName\fR had matched the \fIargv\fR value.  The
  513. synonym mechanism allows multiple \fIargv\fR values to be used for
  514. a single configuration option, such as ``\-background'' and ``\-bg''.
  515. .TP
  516. \fBTK_CONFIG_UID\fR
  517. The value is translated to a \fBTk_Uid\fR
  518. (by passing it to \fBTk_GetUid\fR).  The resulting value
  519. is stored in the target.
  520. .VS
  521. If TK_CONFIG_NULL_OK is specified in \fIspecFlags\fR and the value
  522. is an empty string then the target will be set to NULL.
  523. .TP
  524. \fBTK_CONFIG_WINDOW\fR
  525. The value must be a window path name.  It is translated to a
  526. \fBTk_Window\fR token and the token is stored in the target.
  527. .VE
  528.  
  529. .SH "GROUPED ENTRIES"
  530. .PP
  531. In some cases it is useful to generate multiple resources from
  532. a single configuration value.  For example, a color name might
  533. be used both to generate the background color for a widget (using
  534. TK_CONFIG_COLOR) and to generate a 3-D border to draw around the
  535. widget (using TK_CONFIG_BORDER).  In cases like this it is possible
  536. to specify that several consecutive entries in \fIspecs\fR are to
  537. be treated as a group.  The first entry is used to determine a value
  538. (using its \fIargvName\fR, \fIdbName\fR,
  539. \fIdbClass\fR, and \fIdefValue\fR fields).  The value will be processed
  540. several times (one for each entry in the group), generating multiple
  541. different resources and modifying multiple targets within \fIwidgRec\fR.
  542. Each of the entries after the first must have a NULL value in its
  543. \fIargvName\fR field;  this indicates that the entry is to be grouped
  544. with the entry that precedes it.  Only the \fItype\fR and \fIoffset\fR
  545. fields are used from these follow-on entries.
  546.  
  547. .SH "FLAGS"
  548. .PP
  549. The \fIflags\fR argument passed to \fBTk_ConfigureWidget\fR is used
  550. in conjunction with the \fIspecFlags\fR fields in the entries of \fIspecs\fR
  551. to provide additional control over the processing of configuration
  552. options.  These values are used in three different ways as
  553. described below.
  554. .PP
  555. First, if the \fIflags\fR argument to \fBTk_ConfigureWidget\fR has
  556. the TK_CONFIG_ARGV_ONLY bit set (i.e., \fIflags\fR | TK_CONFIG_ARGV_ONLY != 0),
  557. then the option database and
  558. \fIdefValue\fR fields are not used.  In this case, if an entry in
  559. \fIspecs\fR doesn't match a field in \fIargv\fR then nothing happens:
  560. the corresponding target isn't modified.  This feature is useful
  561. when the goal is to modify certain configuration options while
  562. leaving others in their current state, such as when a \fBconfigure\fR
  563. widget command is being processed.
  564. .PP
  565. Second, the \fIspecFlags\fR field of an entry in \fIspecs\fR may be used
  566. .VS
  567. to control the processing of that entry.  Each \fIspecFlags\fR
  568. field may consists of an OR-ed combination of the following values:
  569. .TP
  570. \fBTK_CONFIG_COLOR_ONLY\fR
  571. If this bit is set then the entry will only be considered if the
  572. display for \fItkwin\fR has more than one bit plane.  If the display
  573. is monochromatic then this \fIspecs\fR entry will be ignored.
  574. .TP
  575. \fBTK_CONFIG_MONO_ONLY\fR
  576. If this bit is set then the entry will only be considered if the
  577. display for \fItkwin\fR has exactly one bit plane.  If the display
  578. is not monochromatic then this \fIspecs\fR entry will be ignored.
  579. .TP
  580. \fBTK_CONFIG_NULL_OK\fR
  581. This bit is only relevant for some types of entries (see the
  582. descriptions of the various entry types above).
  583. If this bit is set, it indicates that an empty string value
  584. for the field is acceptable and if it occurs then the
  585. target should be set to NULL or \fBNone\fR, depending
  586. on the type of the target.
  587. This flag is typically used to allow a
  588. feature to be turned off entirely, e.g. set a cursor value to
  589. \fBNone\fR so that a window simply inherits its parent's cursor.
  590. If this bit isn't set then empty strings are processed as strings,
  591. which generally results in an error.
  592. .TP
  593. \fBTK_CONFIG_DONT_SET_DEFAULT\fR
  594. If this bit is one, it means that the \fIdefValue\fR field of the
  595. entry should only be used for returning the default value in
  596. \fBTk_ConfigureInfo\fR.
  597. In calls to \fBTk_ConfigureWidget\fR no default will be supplied
  598. for entries with this flag set;  it is assumed that the
  599. caller has already supplied a default value in the target location.
  600. This flag provides a performance optimization where it is expensive
  601. to process the default string:  the client can compute the default
  602. once, save the value, and provide it before calling
  603. \fBTk_ConfigureWidget\fR.
  604. .TP
  605. \fBTK_CONFIG_OPTION_SPECIFIED\fR
  606. This bit is set and cleared by \fBTk_ConfigureWidget\fR.  Whenever
  607. \fBTk_ConfigureWidget\fR returns, this bit will be set in all the
  608. entries where a value was specified in \fIargv\fR.
  609. It will be zero in all other entries.
  610. This bit provides a way for clients to determine which values
  611. actually changed in a call to \fBTk_ConfigureWidget\fR.
  612. .VE
  613. .PP
  614. The TK_CONFIG_MONO_ONLY and TK_CONFIG_COLOR_ONLY flags are typically
  615. used to specify different default values for
  616. monochrome and color displays.  This is done by creating two
  617. entries in \fIspecs\fR that are identical except for their
  618. \fIdefValue\fR and \fIspecFlags\fR fields.  One entry should have
  619. the value TK_CONFIG_MONO_ONLY in its \fIspecFlags\fR and the
  620. default value for monochrome displays in its \fIdefValue\fR;  the
  621. other entry entry should have the value TK_CONFIG_COLOR_ONLY in
  622. its \fIspecFlags\fR and the appropriate \fIdefValue\fR for
  623. color displays.
  624. .PP
  625. Third, it is possible to use \fIflags\fR and \fIspecFlags\fR
  626. together to selectively disable some entries.  This feature is
  627. not needed very often.  It is useful in cases where several
  628. similar kinds of widgets are implemented in one place.  It allows
  629. a single \fIspecs\fR table to be created with all the configuration
  630. options for all the widget types.  When processing a particular
  631. widget type, only entries relevant to that type will be used.  This
  632. effect is achieved by setting the high-order bits (those in positions
  633. equal to or greater than TK_CONFIG_USER_BIT) in \fIspecFlags\fR
  634. values or in \fIflags\fR.  In order for a particular entry in
  635. \fIspecs\fR to be used, its high-order bits must match exactly
  636. the high-order bits of the \fIflags\fR value passed to
  637. \fBTk_ConfigureWidget\fR.  If a \fIspecs\fR table is being used
  638. for N different widget types, then N of the high-order bits will
  639. be used.  Each \fIspecs\fR entry will have one of more of those
  640. bits set in its \fIspecFlags\fR field to indicate the widget types
  641. for which this entry is valid.  When calling \fBTk_ConfigureWidget\fR,
  642. \fIflags\fR will have a single one of these bits set to select the
  643. entries for the desired widget type.  For a working example of
  644. this feature, see the code in tkButton.c.
  645.  
  646. .SH TK_OFFSET
  647. .PP
  648. The \fBTk_Offset\fR macro is provided as a safe way of generating
  649. the \fIoffset\fR values for entries in Tk_ConfigSpec structures.
  650. It takes two arguments:  the name of a type of record, and the
  651. name of a field in that record.  It returns the byte offset of
  652. the named field in records of the given type.
  653.  
  654. .SH TK_CONFIGUREINFO
  655. .PP
  656. The \fBTk_ConfigureInfo\fR procedure may be used to obtain
  657. information about one or all of the options for a given widget.
  658. Given a token for a window (\fItkwin\fR), a table describing the
  659. configuration options for a class of widgets (\fIspecs\fR), a
  660. pointer to a widget record containing the current information for
  661. a widget (\fIwidgRec\fR), and a NULL \fIargvName\fR argument,
  662. \fBTk_ConfigureInfo\fR generates a string describing all of the
  663. configuration options for the window.  The string is placed
  664. in \fIinterp->result\fR.  Under normal circumstances
  665. it returns TCL_OK;  if an error occurs then it returns TCL_ERROR
  666. and \fIinterp->result\fR contains an error message.
  667. .PP
  668. If \fIargvName\fR is NULL, then the value left in
  669. \fIinterp->result\fR by \fBTk_ConfigureInfo\fR
  670. consists of a list of one or more entries, each of which describes
  671. one configuration option (i.e. one entry in \fIspecs\fR).  Each
  672. entry in the list will contain either two or five values.  If the
  673. corresponding entry in \fIspecs\fR has type TK_CONFIG_SYNONYM, then
  674. the list will contain two values:  the \fIargvName\fR for the entry
  675. and the \fIdbName\fR (synonym name).  Otherwise the list will contain
  676. five values:  \fIargvName\fR, \fIdbName\fR, \fIdbClass\fR, \fIdefValue\fR,
  677. and current value.  The current value is computed from the appropriate
  678. field of \fIwidgRec\fR by calling procedures like \fBTk_NameOfColor\fR.
  679. .PP
  680. If the \fIargvName\fR argument to \fBTk_ConfigureInfo\fR is non-NULL,
  681. then it indicates a single option, and information is returned only
  682. for that option.  The string placed in \fIinterp->result\fR will be
  683. a list containing two or five values as described above;  this will
  684. be identical to the corresponding sublist that would have been returned
  685. if \fIargvName\fR had been NULL.
  686. .PP
  687. The \fIflags\fR argument to \fBTk_ConfigureInfo\fR is used to restrict
  688. the \fIspecs\fR entries to consider, just as for \fBTk_ConfigureWidget\fR.
  689.  
  690. .SH "CUSTOM OPTION TYPES"
  691. .PP
  692. .VS
  693. Applications can extend the built-in configuration types with additional
  694. configuration types by writing procedures to parse and print options
  695. of the a type and creating a structure pointing to those procedures:
  696. .DS
  697. .ta 1c 2c 3c
  698. typedef struct Tk_CustomOption {
  699.     Tk_OptionParseProc *\fIparseProc\fR;
  700.     Tk_OptionPrintProc *\fIprintProc\fR;
  701.     ClientData \fIclientData\fR;
  702. } Tk_CustomOption;
  703.  
  704. typedef int Tk_OptionParseProc(
  705.     ClientData \fIclientData\fR,
  706.     Tcl_Interp *\fIinterp\fR,
  707.     Tk_Window \fItkwin\fR,
  708.     char *\fIvalue\fR,
  709.     char *\fIwidgRec\fR,
  710.     int \fIoffset\fR);
  711.  
  712. typedef char *Tk_OptionPrintProc(
  713.     ClientData \fIclientData\fR,
  714.     Tk_Window \fItkwin\fR,
  715.     char *\fIwidgRec\fR,
  716.     int \fIoffset\fR,
  717.     Tcl_FreeProc **\fIfreeProcPtr\fR);
  718. .DE
  719. .LP
  720. The Tk_CustomOption structure contains three fields, which are pointers
  721. to the two procedures and a \fIclientData\fR value to be passed to those
  722. procedures when they are invoked.  The \fIclientData\fR value typically
  723. points to a structure containing information that is needed by the
  724. procedures when they are parsing and printing options.
  725. .LP
  726. The \fIparseProc\fR procedure is invoked by
  727. \fBTk_ConfigureWidget\fR to parse a string and store the resulting
  728. value in the widget record.
  729. The \fIclientData\fR argument is a copy of the \fIclientData\fR
  730. field in the Tk_CustomOption structure.
  731. The \fIinterp\fR argument points to a Tcl interpreter used for
  732. error reporting.  \fITkwin\fR is a copy of the \fItkwin\fR argument
  733. to \fBTk_ConfigureWidget\fR.  The \fIvalue\fR argument is a string
  734. describing the value for the option;  it could have been specified
  735. explicitly in the call to \fBTk_ConfigureWidget\fR or it could
  736. come from the option database or a default.
  737. \fIValue\fR will never be a null pointer but it may point to
  738. an empty string.
  739. \fIRecordPtr\fR is the same as the \fIwidgRec\fR argument to
  740. \fBTk_ConfigureWidget\fR;  it points to the start of the widget
  741. record to modify.
  742. The last argument, \fIoffset\fR, gives the offset in bytes from the start
  743. of the widget record to the location where the option value is to
  744. be placed.  The procedure should translate the string to whatever
  745. form is appropriate for the option and store the value in the widget
  746. record.  It should normally return TCL_OK, but if an error occurs
  747. in translating the string to a value then it should return TCL_ERROR
  748. and store an error message in \fIinterp->result\fR.
  749. .LP
  750. The \fIprintProc\fR procedure is called
  751. by \fBTk_ConfigureInfo\fR to produce a string value describing an
  752. existing option.
  753. Its \fIclientData\fR, \fItkwin\fR, \fIwidgRec\fR, and \fIoffset\fR
  754. arguments all have the same meaning as for Tk_OptionParseProc
  755. procedures.
  756. The \fIprintProc\fR procedure should examine the option whose value
  757. is stored at \fIoffset\fR in \fIwidgRec\fR, produce a string describing
  758. that option, and return a pointer to the string.
  759. If the string is stored in dynamically-allocated memory, then
  760. the procedure must set \fI*freeProcPtr\fR to the address of
  761. a procedure to call to free the string's memory;  \fBTk_ConfigureInfo\fR
  762. will call this procedure when it is finished with the string.
  763. If the result string is stored in static memory then \fIprintProc\fR
  764. need not do anything with the \fIfreeProcPtr\fR argument.
  765. .LP
  766. Once \fIparseProc\fR and \fIprintProc\fR have been defined and a
  767. Tk_CustomOption structure has been created for them, options of this
  768. new type may be manipulated with Tk_ConfigSpec entries whose \fItype\fR
  769. fields are TK_CONFIG_CUSTOM and whose \fIcustomPtr\fR fields point
  770. to the Tk_CustomOption structure.
  771. .VE
  772.  
  773. .SH EXAMPLES
  774. .PP
  775. Although the explanation of \fBTk_ConfigureWidget\fR is fairly
  776. complicated, its actual use is pretty straightforward.
  777. The easiest way to get started is to copy the code
  778. from an existing widget.
  779. The library implementation of frames
  780. (tkFrame.c) has a simple configuration table, and the library
  781. implementation of buttons (tkButton.c) has a much more complex
  782. table that uses many of the fancy \fIspecFlags\fR mechanisms.
  783.  
  784. .SH KEYWORDS
  785. anchor, bitmap, boolean, border, cap style, color, configuration options,
  786. cursor, custom, double, font, integer, join style, justify, millimeters,
  787. pixels, relief, synonym, uid
  788.